﻿function GetXmlHttpObj()
{
    var XmlHttpObj = null;
    try
    { 
        if(window.ActiveXObject)
        { 
            for(var i = 5;i;i--)
            { 
                try
                {
                    if( i == 2 )
                    { 
                        XmlHttpObj = new ActiveXObject( "Microsoft.XMLHTTP" ); 
                    }
                    else
                    { 
                        XmlHttpObj = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" ); 
                    } 
                    XmlHttpObj.setRequestHeader("Content-Type","text/xml"); 
                    XmlHttpObj.setRequestHeader("Content-Type","utf-8"); 
                    break;
                }
                catch(e)
                {}
            }
        }
        else if( window.XMLHttpRequest )
        { 
            XmlHttpObj = new XMLHttpRequest(); 
            if (XmlHttpObj.overrideMimeType) 
            {
                XmlHttpObj.overrideMimeType('text/xml');
            }
        }
    }
    catch(e)
    {}
    return XmlHttpObj;
}


function XmlHttpGetMethod(uri)
{
    var XmlHttp = GetXmlHttpObj();
    if(XmlHttp == null)
    {
        alert('很抱歉，你的浏览器版本不支持，操作终止');
        return;
    }
    XmlHttp.open("GET",uri,false);
    XmlHttp.send();
    return XmlHttp;
}

function XmlHttpGetMethodSyn(uri, target, backFunc) {
    var XmlHttp = GetXmlHttpObj();
    if (XmlHttp == null) {
        alert('很抱歉，你的浏览器版本不支持，操作终止');
        return;
    }
    XmlHttp.open("GET", uri, true);
    XmlHttp.send();
    XmlHttp.onreadystatechange = function() {
        if (XmlHttp.readyState == 4) {
            if (XmlHttp.status == 200) {
                target.innerHTML = "";
                var str = XmlHttp.responseText;
                if (str.length > 0 && str != "--") {
                    target.innerHTML += XmlHttp.responseText;
                }
                if (target.innerHTML.length > 0) {
                    if (target.style["display"] == "none") {
                        target.style["display"] = "";
                    }
                }
                if (backFunc != undefined && backFunc) {
                    backFunc(target);
                }
            }
        }
    }
}

function XmlHttpGetMethodSy(uri, target, js) {
    var XmlHttp = GetXmlHttpObj();
    if (XmlHttp == null) {
        alert('很抱歉，你的浏览器版本不支持，操作终止');
        return;
    }
    XmlHttp.open("GET", uri, true);
    XmlHttp.send();
    XmlHttp.onreadystatechange = function() {
        if (XmlHttp.readyState == 4) {
            if (XmlHttp.status == 200) {
                setSubNavBody(target, XmlHttp.responseText);
                if (js != "") {
                    eval(js);
                }
            }
        }
    }
}

function setSubNavBody(obj, content) {
    var iframeDiv = "<iframe style=\"position: absolute; z-index: -1; filter: alpha(opacity=0);\"></iframe>";
    if (obj) {
        obj.innerHTML = '';
        obj.innerHTML += iframeDiv;
        obj.innerHTML += content;
        obj.style["width"] = obj.offsetWidth + "px";
    }
}

function XmlHttpPostMethod(uri,parmsStr)
{
    var XmlHttp = GetXmlHttpObj();
    if(XmlHttp == null)
    {
        alert('很抱歉，你的浏览器版本不支持，操作终止');
        return;
    }
    XmlHttp.open("POST",uri,false);    
    XmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    XmlHttp.send(parmsStr);
    return XmlHttp;
}

function XmlHttpGetMethodText(uri)
{
    var XmlHttp = XmlHttpGetMethod(uri);
    return XmlHttp.responseText;
}

function XmlHttpGetMethodTextSy(uri, target) {
    XmlHttpGetMethodSy(uri, target);
}

function XmlHttpPostMethodText(uri,parmsStr)
{
    var XmlHttp = XmlHttpPostMethod(uri, parmsStr);
    return XmlHttp.responseText;
}

function XmlHttpGetMethodXml(uri)
{
    var XmlHttp = XmlHttpGetMethod(uri);
    return XmlHttp.responseXML;
}

function XmlHttpPostMethodXml(uri,parmsStr)
{
    var XmlHttp = XmlHttpPostMethod(uri, parmsStr);
    return XmlHttp.responseXML;
}